package com.cafeauto.socketio;

import java.io.Serializable;
import java.util.Date;

import com.efast.cafe.util.date.DateUtils;

import net.sf.json.JSONObject;
/**
 * 消息推送 客户端回调消息格式
 * @author fxm
 *
 */
public class SocketCallbackData implements Serializable{
	
	public static String ERROR_SESSION_TIMEOUT="SESSION_TIMEOUT";
	public static String ERROR_SYSTEM_ERROR="SYSTEM_ERROR";
	public static String ERROR_VERSION_ERROR="VERSION_ERROR";
	public static String ERROR_HMAC_ERROR="HMAC_ERROR";
	public static String ERROR_DECODE_ERROR="DECODE_ERROR";
	public static String ERROR_TIME_ERROR="TIME_ERROR";
	public static String ERROR_DATA_ERROR="DATA_ERROR";
	public static String ERROR_DATA_REPETITION="DATA_REPETITION";
	public static String ERROR_CONFIG_ERROR="CONFIG_ERROR";

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private SocketCallbackMessage message;
	private boolean success=true;
	private String hmac;
	private String errorCode;
	private String errorMessage;
	private String time;//当前服务器时间
	public SocketCallbackMessage getMessage() {
		return message;
	}
	public void setMessage(SocketCallbackMessage message) {
		this.message = message;
	}
	public String getHmac() {
		return hmac;
	}
	public void setHmac(String hmac) {
		this.hmac = hmac;
	}
	
	public String getTime() {
		return time;
	}
	public void setTime(String time) {
		this.time = time;
	}
	
	public boolean isSuccess() {
		return success;
	}
	public void setSuccess(boolean success) {
		this.success = success;
	}
	public String getErrorCode() {
		return errorCode;
	}
	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}
	public String getErrorMessage() {
		return errorMessage;
	}
	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}
	
	public String callbackResult(boolean success,String hmac,String errorCode,String errorMessage,SocketCallbackMessage message){
		JSONObject jo = new JSONObject();
		JSONObject msg = new JSONObject();
		msg.put("messageId", null!=message? (message.getMessageId()!=null?message.getMessageId():""):"");
		msg.put("busObject", null!=message?(message.getBusObject()!=null?message.getBusObject():""):null);
		jo.put("message", msg);
		jo.put("success", success);
		jo.put("hmac", null==hmac?"":hmac);
		jo.put("errorCode", null==errorCode?"":errorCode);
		jo.put("errorMessage", null==errorMessage?"":errorMessage);
		jo.put("time", DateUtils.format(new Date(), DateUtils.FORMAT_DATE_YYYY_MM_DD_HH_MM));
		return jo.toString();
	}
	
}
